package com.blkkj.huan.Controller;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.iot.model.v20170420.QueryDeviceRequest;
import com.aliyuncs.iot.model.v20170420.QueryDeviceResponse;
import com.blkkj.huan.util.LogUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.blkkj.huan.util.BaseTest.executeTest;

@RestController
public class QueryDeviceController {

    @PostMapping("/QueryDevice")
    public String QueryDevice(String productKey, Integer pageSize, Integer currentPage){
        //分页查询设备
        QueryDeviceTest(productKey, 10, 0);
        return "huan";
    }

    /**
     * 查询设备列表
     *
     * @param productKey 产品PK
     * @param pageSize 每页显示条数 非必须
     * @param currentPage 当前页 非必须
     */
    public static void QueryDeviceTest(String productKey, Integer pageSize, Integer currentPage) {
        QueryDeviceRequest request = new QueryDeviceRequest();
        request.setProductKey(productKey);
        request.setPageSize(pageSize);
        request.setCurrentPage(currentPage);
        QueryDeviceResponse response = (QueryDeviceResponse)executeTest(request);
        if (response != null && response.getSuccess() != false) {
            LogUtil.print("查询设备成功！ " + JSONObject.toJSONString(response));
        } else {
            LogUtil.error("查询设备失败！requestId:" + response.getRequestId() + "原因：" + response.getErrorMessage());
        }

    }
}
